<?php

class Ext_Image_Show_Build
{
    protected $_imageFilePath;
    protected $_imageFileName;
    
    public function __construct($imageId)
    {
        $_appModelDbTableImage = App_Model_DbTable_Image::getInstance();
        $imageRow = $_appModelDbTableImage->getRowById($imageId);

        $_path = $imageRow['path'];
        if (substr(PHP_OS, 0, 3) == 'WIN')
        {
            $_path = str_replace(DIRECTORY_SEPARATOR, '/', $_path);
        }
        $this->_imageFilePath = rtrim($_path, '/') . '/';
        $this->_imageFileName = $imageRow['name'];
    }
    
    public function url($sizeName = null)
    {
        $_config = Ext_Config::getInstance()->getConfig('image');
        if($sizeName == null){
            $url  = rtrim($_config->url, "/") . "/source/" . $this->_imageFilePath . $this->_imageFileName;
        }else{
            $url  = rtrim($_config->url, "/") . "/resize/" . $sizeName . "/" . $this->_imageFilePath . $this->_imageFileName;
        }
        return $url;    
    }
}
